//
//  HMMineHeaderFrame.m
//  欢乐美食
//
//  Created by MacOS on 15/7/11.
//  Copyright (c) 2015年 遇水. All rights reserved.
//

#import "HMMineHeaderFrame.h"

@interface HMMineHeaderFrame()


@end

@implementation HMMineHeaderFrame

- (void)setHeaderData:(HMMineHeader *)headerData
{
    _headerData = headerData;
    
    CGFloat margin = 10;
    CGFloat iconFrameX = 1.8 * margin;
    CGFloat iconFrameY = margin;
    CGFloat iconFrameW = 32;
    CGFloat iconFrameH = 34;
    self.iconFrame = CGRectMake(iconFrameX, iconFrameY, iconFrameW, iconFrameH);
    
    CGFloat userNameFrameX = CGRectGetMaxX(self.iconFrame) + 2 * margin;
    CGFloat userNameFrameY = 2 * margin;
    CGSize size = [headerData.userName sizeWithFont: [UIFont systemFontOfSize:HMMineTextSizeFont] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    CGFloat userNameFrameW = size.width;
    CGFloat userNameFrameH = size.height;
    self.userNameFrame = CGRectMake(userNameFrameX, userNameFrameY, userNameFrameW, userNameFrameH);
    
    CGFloat arrowFrameW = 7;
    CGFloat arrowFrameH = 12;
    CGFloat arrowFrameX = [UIScreen mainScreen].bounds.size.width -  arrowFrameW - margin - 5;
    CGFloat arrowFrameY = 2.5 * margin;
    self.arrowFrame = CGRectMake(arrowFrameX, arrowFrameY, arrowFrameW, arrowFrameH);
    
    CGFloat nameBackFrameW = [UIScreen mainScreen].bounds.size.width;
    CGFloat nameBackFrameH = CGRectGetMaxY(self.iconFrame) + margin;
    CGFloat nameBackFrameX = 0;
    CGFloat nameBackFrameY = 0;
    self.nameBackFrame = CGRectMake(nameBackFrameX, nameBackFrameY, nameBackFrameW, nameBackFrameH);
    
    
    //代金券
    CGFloat coinIconX = margin;
    CGFloat coinIconY = margin;
    CGFloat coinIconW = 40;
    CGFloat coinIconH = 40;
    self.coinIconFrame = CGRectMake(coinIconX, coinIconY, coinIconW, coinIconH);
    
    CGFloat coinLabelX =  CGRectGetMaxX(self.coinIconFrame) + margin * 2;
    CGFloat coinLabelY = coinIconY + margin;
    CGSize coinLabelSize = [@"代金券" sizeWithFont: [UIFont systemFontOfSize:HMMineTextSizeFont] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    CGFloat coinLabelW = coinLabelSize.width;
    CGFloat coinLabelH = coinLabelSize.height;
    self.coinLabelFrame = CGRectMake(coinLabelX, coinLabelY, coinLabelW, coinLabelH);
    
    CGFloat coinTextX = CGRectGetMaxX(self.coinLabelFrame) + margin;
    CGFloat coinTextY = coinLabelY;
    CGSize coinTextSize = [headerData.coin sizeWithFont: [UIFont systemFontOfSize:HMMineTextSizeFont] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    CGFloat coinTextW = coinTextSize.width;
    CGFloat coinTextH = coinTextSize.height;
    self.coinTextFrame = CGRectMake(coinTextX, coinTextY, coinTextW, coinTextH);
    
    CGFloat coinFrameW = [UIScreen mainScreen].bounds.size.width * 0.5;
    CGFloat coinFrameY = CGRectGetMaxY(self.nameBackFrame) + margin;
    self.coinFrame = CGRectMake(0, coinFrameY, coinFrameW, coinIconH + 2 * margin);
    
    
    // 我的收藏
    // CGRectGetMaxX(self.coinFrame) + 
    CGFloat collectionIconX = margin;
    CGFloat collectionIconY = margin;
    CGFloat collectionIconW = coinIconW;
    CGFloat collectionIconH = coinIconH;
    self.collectionIconFrame = CGRectMake(collectionIconX, collectionIconY, collectionIconW, collectionIconH);
    
    CGFloat collectionLabelX = CGRectGetMaxX(self.collectionIconFrame) + margin;
    CGFloat collectionLabelY = collectionIconY + margin;
    CGSize collectionLabelSize = [@"我的收藏" sizeWithFont: [UIFont systemFontOfSize:HMMineTextSizeFont] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    CGFloat collectionLabelW = collectionLabelSize.width;
    CGFloat collectionLabelH = collectionLabelSize.height;
    self.collectionLabelFrame = CGRectMake(collectionLabelX, collectionLabelY, collectionLabelW, collectionLabelH);
    
    CGFloat collectionTextX = CGRectGetMaxX(self.collectionLabelFrame) + margin;
    CGFloat collectionTextY = collectionLabelY;
    CGSize collectionTextSize = [headerData.collection sizeWithFont: [UIFont systemFontOfSize:HMMineTextSizeFont] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    CGFloat collectionTextW = collectionTextSize.width;
    CGFloat collectionTextH = collectionTextSize.height;
    self.collectionTextFrame = CGRectMake(collectionTextX, collectionTextY, collectionTextW, collectionTextH);
    
    self.collectionFrame = CGRectMake(CGRectGetMaxX(self.coinFrame), coinFrameY, coinFrameW, coinIconH + 2 * margin);
    
    self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, CGRectGetMaxY(self.coinFrame));
}

@end
